from flask import Blueprint, request, jsonify
import datetime
from db import db1

bp_effet = Blueprint("effect", __name__)


@bp_effet.route('/ypM', methods=['GET'])
def ypM():
    sql = "select * from type"
    res = db1.findall(sql)
    return jsonify({'code': 200, 'list': res})


@bp_effet.route('/recorM', methods=['GET'])
def recorM():
    sort = request.args.get('sort')
    id = request.args.get('typeid')
    if id == '0':
        sql = "select * from recor order by money %s" % (sort)
    else:
        sql = "select * from recor where typeid=%d order by money  %s" % (int(id), sort)
    res = db1.findall(sql)
    list = []
    for i in res:
        dict = {'id': i['id'], 'money': float(i['money']),
                'stime': datetime.datetime.strftime(i['stime'], '%Y-%m-%d'),
                'etime': datetime.datetime.strftime(i['etime'], '%Y-%m-%d')}
        list.append(dict)
    return jsonify({'code': 200, 'list': list})


@bp_effet.route('/showM')
def showM():
    id = request.args.get('id')
    sql = "select * from where id=%d" % (int(id))
    res = db1.find(sql)
    